#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
 * 签名工具类
 *
 * author: liuxh 2017.8.11
 *
 * 
 */
 '''
import hmac, hashlib 
from hashlib import sha1
 
class SignUtil(object):
    def __init__(self):
        pass
    
    def sign(self, Method, key, **params):        
        """ 数字签名程序"""
        #字典排序生成规范化请求字符串
        sortedKey = sorted(params.iteritems(), key=lambda d:d[0] )
        temp = sortedKey[0]+sortedKey[1]+sortedKey[2]+sortedKey[3]
        list_str = ''.join(temp)
        return self.encryptHMAC(list_str, key, Method)
        
        """HMAC加密"""
    def encryptHMAC(self, content, key, Method):    
        a = hmac.new(key, content, Method)
        return a.digest().encode('hex').rstrip('')
       

